package com.test1231;

public class Test02 {
    public static void main(String[] args) {
        // (2)根据需求写出实现代码

        // 创建公司
        CC c = new CC("IBM");

        // 创建员工：名字、年龄、工资  --- EE员工类
        EE e1 = new EE("张三", 30, 3000);
        EE e2 = new EE("李四", 40, 4000);
        EE e3 = new EE("王五", 50, 5000);

        // 公司添加员工(数组存储员工)   公司中方法add
        c.add(e1);
        c.add(e2);
        c.add(e3);
        c.add("赵六", 60, 6000);

        // 打印员工信息         公司中方法printAll
        c.printAll();
        System.out.println();

        // 找出年龄最大员工
        EE x = c.m1();
        System.out.println(x);
        // 找出工资最低工资
        EE y = c.m2();
        System.out.println(y);
        // 找出李四员工
        EE z = c.m3("李四");
        System.out.println(z);
        // 求平均工资
        double d = c.m4();
        System.out.println(d);

        // 自己设计方法并实现：所有员工工资涨500
        c.m5(500);

        // 自己设计方法并实现：打印工资高于平均工资的员工
        c.m6();

        // 自己设计方法并实现：返回工资高于平均工资的员工
        EE n = c.m7();
        System.out.println(n);
    }
}
class CC{
    private String name;
    private EE[] emp = new  EE[4];
    private int index=0;

    public CC(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    public void add(EE e){
        emp[index++] =e;//差个数组动态扩容

    }
    public void add(String name,int age,int wage){
        emp[index++] =new EE(name,age,wage);
    }
    public void printAll(){
        for(int i=0;i<emp.length;i++){
            System.out.println(emp[i].toString());
        }
    }
    public EE m1(){//找出年龄最大员工
        EE max = emp[0];
        for(int i =1;i<emp.length;i++){
            if(max.getAge()<emp[i].getAge()){
                max = emp[i];
            }
        }
        return max;
    }
    public EE m2(){//工资最低员工
        EE min = emp[0];//工资最低
        for(int i =1;i<emp.length;i++){
            if(min.getWage()>emp[i].getWage()){
                min = emp[i];
            }
        }
        return min;
    }
    public EE m3(String name){
        for(int i =0;i<emp.length;i++){
            if(emp[i].getE_Name()==name){
                return emp[i];
            }
        }
        return null;
    }
    public double m4(){//平均工资
        int sum = 0;
        for(int i =0;i<emp.length;i++){
            sum+=emp[i].getWage();
        }
        double avg = sum/emp.length;
        return avg;
    }
    public void m5(int wag){//工资加500
        for(int i=0;i<emp.length;i++){
            emp[i].setWage(emp[i].getWage()+wag);
        }
    }
    public void m6(){//打印高于平均工资的员工
        for(int i=0;i<emp.length;i++){
            if(m4()<emp[i].getWage()){
                System.out.println(emp[i]);
            }
        }
    }
    public EE m7(){//返回高于平均工资的员工
        for(int i=0;i<emp.length;i++){
            if(m4()<emp[i].getWage()){
                return emp[i];
            }
        }
        return null;
    }

}
class EE{
    private String e_Name;
    private int age;
    private int wage;
    private CC  com;

    public EE() {
    }

    public EE(String e_Name, int age, int wage) {
        this.e_Name = e_Name;
        this.age = age;
        this.wage = wage;
    }

    public EE(String e_Name, int age, int wage, CC com) {
        this.e_Name = e_Name;
        this.age = age;
        this.wage = wage;
        this.com = com;
    }

    public String getE_Name() {
        return e_Name;
    }

    public void setE_Name(String e_Name) {
        this.e_Name = e_Name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getWage() {
        return wage;
    }

    public void setWage(int wage) {
        this.wage = wage;
    }

    public CC getCom() {
        return com;
    }

    public void setCom(CC com) {
        this.com = com;
    }

    @Override
    public String toString() {
        return "EE{" +
                "e_Name='" + e_Name + '\'' +
                ", age=" + age +
                ", wage=" + wage +
                ", com=" + com +
                '}';
    }
}